<?php require_once 'header.php';?>    
<!-- DataTables Responsive CSS -->
    <link href="sb2/vendor/datatables-responsive/dataTables.responsive.css" rel="stylesheet">

        <!-- Page Content -->
        <div id="page-wrapper">
            <div class="container-fluid">
                <div class="row">
                <div class="col-lg-12">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            <?php echo XXF_LNAME?><br>
                            <div style="border: 1px black solid;padding:3px;">
                                文件标题：<input type="text" id="ftitle">
                                <br>文件类型：
                                <select id="ftype">
                                	<?php foreach (explode(",",gconf("web", "filetype")) as $v){?>
                                	<option><?php echo $v?></option>
                                	<?php }?>
                                </select><br>允许[<?php echo gconf("web", "allowFile")?>]，单个限10MB<br>
                                <span style="border: 1px #aaa solid;padding:3px;">
                                <input type="file" id="upfile" style="display:inline;width:90%"></span>
                                 <br><br><input id="sub" type="button" value="上传" onclick="upload()">
                            </div>
                        </div>
                        <!-- /.panel-heading -->
                        <div class="panel-body">
                            <table width="100%" class="table table-striped table-bordered table-hover" id="dataTables-example">
                                <thead>
                                    <tr>
                                        <th>序号</th>
                                        <th>文件标题</th>
                                        <th>文件类型</th>
                                        <th>文件大小</th>
                                        <th>上传时间</th>
                                        <th>操作</th>
                                    </tr>
                                </thead>
                                <tbody>
                                	<?php
                                	$i=0;
                                	foreach ($result as $row){$i++;
                                	?>
                                    <tr class="<?php echo $i%2==0?"even":"odd";?> gradeA">
                                    	<td><?php echo $i;?></td>
                                        <td><a href="uploader/filem/<?php echo $row['fname']?>" target="_blank"><?php echo $row['ftitle']?></a></td>
                                        <td><?php echo $row['ftype']?></td>
                                        <td><?php echo round($row['fsize']/1024/1024,2)?>MB</td>
                                        <td><?php echo $row['atime']?></td>
                                        <td><input type="button" value="删除" onclick="del(<?php echo $row['id']?>,'<?php echo $row['fname']?>')"></td>
                                    </tr>
                                	<?php 
                                	}
                                	?>
                                </tbody>
                            </table>
                        </div>
                        <!-- /.panel-body -->
                    </div>
                    <!-- /.panel -->
                </div>
                <!-- /.col-lg-12 -->
            </div>
            <!-- /.row -->
             </div>
        </div>
        <!-- /#page-wrapper -->
  </div>
        <!-- DataTables JavaScript -->
<?php require_once 'bottom.php';?>
    <script src="sb2/vendor/datatables/js/jquery.dataTables.js"></script>
    <script src="sb2/vendor/datatables-plugins/dataTables.bootstrap.min.js"></script>
    <script src="sb2/vendor/datatables-responsive/dataTables.responsive.js"></script>
    <script>
    $(document).ready(function() {
        $('#dataTables-example').DataTable({
            responsive: true,
            "aaSorting": [[ 0, "desc" ]],
            "aLengthMenu": [ 50, 25, 10, 1]
        });
    });
   var uf=$("#upfile").xxfile({
		url:"filem",
		accept:"<?php echo gconf("web", "allowFile")?>",
		maxsize:10*1024*1024,
		autoup:false
	},function(files){
		$ft=$("#ftitle");
		if($ft.val().length<2){
			$ft.val(files[0].name);
		}
	});
	function upload(){
		var ftitle=$("#ftitle").val();
		var ftype=$("#ftype").val();
		if(ftitle.length<1){
			$.xalert("文件标题不能为空！");
			return ;
		}
		uf.startup({
			data:{
				ftitle:ftitle,
				ftype:ftype,
				type:'upload'
			},
			success:function(data){
				if(data==1){
					$.xalert("上传成功",function(){
						window.location.reload();
					});
				}else{
					$.xalert(data);
				}
			}
		});
	}
	function del(id,fname){
		$.xconfirm("删除后无法恢复，确定要删除此条记录么？",function(data){
 			if(data){
				$.xloading(1);
				$.xxpost("filem",{
					type:"del"
					,id:id
					,fname:fname
				},function(data){
					$.xloading(0);
					if(data==1){
						$.xalert("删除成功",function(){
							window.location.reload();
						});
					}else{
						$.xalert(data);
					}
				}).error(function(){
					del(id,fname);
				});
			} 
		});
	}
    </script>